package com.letsiot.applications.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import com.letsiot.applications.entity.SysRole;
import com.letsiot.applications.entity.enums.RoleType;
import com.letsiot.applications.repository.SysRoleMapper;
import com.letsiot.applications.service.SysRoleService;
import com.letsiot.common.data.IdUtil;

@Service
public class SysRoleServiceImpl implements SysRoleService {

    @Autowired
    private SysRoleMapper sysRoleMapper;

    @Override
    public int save(SysRole entity) {
        if (entity.getId() == null) {
            entity.setId(IdUtil.getId());
        }
        return sysRoleMapper.insertSelective(entity);
    }

    @Override
    public int delete(Long id) {
        return sysRoleMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int update(SysRole entity) {
        return sysRoleMapper.updateByPrimaryKeySelective(entity);
    }

    @Override
    public SysRole findById(Long id) {
        return sysRoleMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<SysRole> getAll() {
        return sysRoleMapper.getAll();
    }

    @Override
    public Page<SysRole> findByType(RoleType roleType, Pageable pageable) {
        Page<SysRole> page = sysRoleMapper.findByType(roleType, pageable);
        return page;
    }
}
